package com.itheima.controller.backend;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkitem")
@Slf4j
public class CheckItemController {

    @Autowired
    private CheckItemService bookingService;

    //新增
    @PostMapping("/add")
    public Result addCheckItem(@RequestBody CheckItem checkItem){
        bookingService.addCheckItem(checkItem);
        Result result =  new Result();
        result.setFlag(true);
        result.setMessage(MessageConstant.ADD_CHECKITEM_SUCCESS);
        return result;
    }

    // 根据id删除检查项
    @GetMapping("/delete")
    public Result deleteCheckItemById(@RequestParam Integer id){
        bookingService.deleteBooking(id);

        Result result =  new Result();
        result.setFlag(true);
        result.setMessage(MessageConstant.DELETE_CHECKITEM_SUCCESS);
        return result;

    }

    // 根据检查组id查询关联的检查项
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam Integer checkgroupId){
        Result result = new Result();
        result.setData(bookingService.findCheckItemIdsByCheckGroupId(checkgroupId));
        result.setFlag(true);
        result.setMessage(MessageConstant.QUERY_CHECKITEM_SUCCESS);

        return result;
    }

    @PostMapping("/edit")
    public Result updateBooking(@RequestBody CheckItem checkItem){
        bookingService.updateBooking(checkItem);
        Result result =  new Result();
        result.setFlag(true);
        result.setMessage(MessageConstant.EDIT_CHECKITEM_SUCCESS);
        return result;
    }
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询检查项:" + queryPageBean);
        Result result = new Result();
        result.setData(bookingService.findPage(queryPageBean));
        result.setFlag(true);
        result.setMessage(MessageConstant.QUERY_CHECKITEM_SUCCESS);

        return result;
    }
    @GetMapping("/findAll")
    public Result getAllBooking(){
        Result result = new Result();
        result.setData(bookingService.getAllBooking());
        result.setFlag(true);
        result.setMessage(MessageConstant.QUERY_CHECKITEM_SUCCESS);

        return result;
    }

    @GetMapping("/findById")
    public Result getBookingById(@RequestParam Integer id){
        Result result = new Result();
        result.setData(bookingService.getBookingById(id));
        result.setFlag(true);
        result.setMessage(MessageConstant.QUERY_CHECKITEM_SUCCESS);

        return result;
    }



}
